<template>
  <div class="comments-container">
    <el-row>
      <el-col :span="18" :offset="4">
        <el-card class="m_t25">
          <template #header>
            <div class="flex-row justify-between">
              <div class="flex1">
                <el-breadcrumb separator="/">
                  <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                  <el-breadcrumb-item :to="{ name: 'frontNews' }" v-if="$route.query.list">用药说明列表</el-breadcrumb-item>
                  <el-breadcrumb-item>{{ item.medicineName }} 用药说明详情</el-breadcrumb-item>
                </el-breadcrumb>
              </div>
              <div class="flex-shrink">
                <el-button @click="$router.back()" size="mini">返回</el-button>
              </div>
            </div>
          </template>
          <div class="comments-content">
            <div class="item">
              <el-form label-width="120px">
                <el-form-item label="药品名称：" prop="medicineCode">
                  {{ item.medicineName }}
                </el-form-item>
                <el-form-item label="用法用量：" prop="medicineCode">
                  {{ item.usage }}
                </el-form-item>
                <el-form-item label="用法禁忌：" prop="medicineCode">
                  {{ item.taboo }}
                </el-form-item>
                <el-form-item label="注意事项：" prop="medicineCode">
                  {{ item.attention }}
                </el-form-item>
                <el-form-item label="药品说明：" prop="medicineCode">
                  {{ item.content }}
                </el-form-item>
              </el-form>
              <div class="flex-column">
                <el-image alt="" :src="item.cover" v-if="item.cover&&item.cover.trim().length"/>
              </div>
              <div class="flex-column">
                <el-image alt="" :src="v" v-for="v of item.images||[]" :key="v"/>
              </div>

            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

  </div>
</template>

<script>
import {defineComponent, reactive, ref, toRaw} from "vue"
import {deepClone} from "../utils/helpers";
import Toast from "../utils/Toast";
import News from "../api/modules/News";
import dayjs from "dayjs";
import {usePageMeta} from "../hooks/usePageTableData";
import {useRoute} from "vue-router";

export default defineComponent({
  name: "NewsInfo",
  methods: {
    format(time, layout = 'YYYY-MM-DD HH:mm:ss') {
      return dayjs(time).format(layout)
    }
  },
  setup() {
    const route = useRoute();
    const item = ref([]);
    getNewInfo(); //获取新闻详情
    async function getNewInfo() {
      try {
        const {data} = await News.info(route.query.id);
        const info = data || {};

        let content = {};
        try {
          content = JSON.parse(info.analysis) || {}
          console.log(content)
        } catch (e) {

        }

        item.value = {
          ...info,
          ...content,
        }

      } catch (e) {
        console.log(e);
      }
    }

    return {
      item,
    }
  },
})
</script>

<style lang="scss" scoped>
.comments-content {
  padding: 20px 0;


  .item {
    margin-bottom: 10px;
    padding: 10px;
    border-bottom: solid 1px #f8f8f8;

    &:last-child {
      border-width: 0;
    }

    .head {
      .cover {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        border-width: 0;
      }
    }

  }
}

</style>
